home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / Filezilla Server / FileZilla_Server-0_9_41.exe / source / interface / misc / BrowseForFolder.h < prev    next >
C/C++ Source or Header  |  2011-11-06  |  6KB  |  156 lines

  1. //////////////////////////////////////////////////////////////////////
  2. //
  3. // ShellBrowser.h: interface for the CShellBrowser class.
  4. //
  5. // Copyright 1998 Scott D. Killen
  6. //
  7. //////////////////////////////////////////////////////////////////////
  8.  
  9. #ifndef __SHELLBROWSER_H__
  10. #define __SHELLBROWSER_H__
  11.  
  12. #if _MSC_VER >= 1000
  13. #pragma once
  14. #endif // _MSC_VER >= 1000
  15.  
  16. #include <memory>
  17. #include <shlobj.h>
  18.  
  19. //////////////////////////////////////////////////////////////////////
  20. //
  21. // CShellBrowser
  22. //
  23.  
  24. class CBrowseForFolder
  25. {
  26. public:
  27.     CString FormatLongPath( CString oLongPath ) const;
  28.     CBrowseForFolder(const HWND hParent = NULL, const LPITEMIDLIST pidl = NULL, const int nTitleID = 0);
  29.     CBrowseForFolder(const HWND hParent, const LPITEMIDLIST pidl, const CString& strTitle);
  30.     virtual ~CBrowseForFolder() = 0;
  31.  
  32.     //
  33.     // Set the handle of the owner window for the dialog box.
  34.     //
  35.     void SetOwner(const HWND hwndOwner);
  36.  
  37.     //
  38.     // Set the root of the heirarchy that will be browsed.  Get pidl from SHGetSpecialFolderLocation.
  39.     // This can be set to NULL to use the Virtual Folder that represents the Windows Desktop.
  40.     //
  41.     void SetRoot(const LPITEMIDLIST pidl);
  42.  
  43.     //
  44.     // Access a string that is displayed above the tree view control in the dialog box. This
  45.     // string can be used to specify instructions to the user.  strTitle is a CString containing
  46.     // the text to be displayed.  nTitle is the index of a string resource to be loaded.  The
  47.     // return value is false if the resource could not be loaded.
  48.     //
  49.     CString GetTitle() const;
  50.     void SetTitle(const CString& strTitle);
  51.     bool SetTitle(const int nTitle);
  52.  
  53.     //
  54.     // ulFlags = Value specifying the types of folders to be listed in the dialog box as well as
  55.     //           other options. This member can include zero or more of the following values:
  56.     //
  57.     //          BIF_BROWSEFORCOMPUTER    Only returns computers. If the user selects anything
  58.     //                                   other than a computer, the OK button is grayed.
  59.     //
  60.     //          BIF_BROWSEFORPRINTER     Only returns printers. If the user selects anything 
  61.     //                                   other than a printer, the OK button is grayed.
  62.     //
  63.     //          BIF_DONTGOBELOWDOMAIN    Does not include network folders below the domain level
  64.     //                                   in the tree view control.
  65.     //
  66.     //          BIF_RETURNFSANCESTORS    Only returns file system ancestors. If the user selects
  67.     //                                   anything other than a file system ancestor, the OK
  68.     //                                   button is grayed.
  69.     //
  70.     //          BIF_RETURNONLYFSDIRS     Only returns file system directories. If the user
  71.     //                                   selects folders that are not part of the file system,
  72.     //                                   the OK button is grayed.
  73.     //
  74.     //          BIF_STATUSTEXT           Includes a status area in the dialog box. The callback
  75.     //                                   function can set the status text by sending messages to
  76.     //                                   the dialog box. 
  77.     //
  78.     UINT GetFlags() const;
  79.     void SetFlags(const UINT ulFlags);
  80.  
  81.     //
  82.     // Call GetSelectedFolder to retrieve the folder selected by the user.
  83.     //
  84.     CString GetSelectedFolder() const;
  85.  
  86.     //
  87.     // Function to retreive the image associated with the selected folder. The image is specified
  88.     // as an index to the system image list. 
  89.     //
  90.     int GetImage() const;
  91.  
  92.     //
  93.     // Call SelectFolder to display the dialog and get a selection from the user.  Use
  94.     // GetSelectedFolder and GetImage to get the results of the dialog.
  95.     //
  96.     bool SelectFolder();
  97.  
  98. protected:
  99.     //
  100.     // OnInit is called before the dialog is displayed on the screen.
  101.     //
  102.     virtual void OnInit() const;
  103.  
  104.     //
  105.     // OnSelChanged is called whenever the user selects a different directory.  pidl is the
  106.     // LPITEMIDLIST of the new selection.  Use SHGetPathFromIDList to retrieve the path of the
  107.     // selection.
  108.     //
  109.     virtual void OnSelChanged(const LPITEMIDLIST pidl) const;
  110.  
  111.     //
  112.     // Call EnableOK to enable the OK button on the active dialog.  If bEnable is true then the
  113.     // button is enabled, otherwise it is disabled.
  114.     // NOTE -- This function should only be called within overrides of OnInit and OnSelChanged.
  115.     //
  116.     void EnableOK(const bool bEnable) const;
  117.  
  118.     //
  119.     // Call SetSelection to set the selection in the active dialog.  pidl is the LPITEMIDLIST
  120.     // of the path to be selected.  strPath is a CString containing the path to be selected.
  121.     // NOTE -- This function should only be called within overrides of OnInit and OnSelChanged.
  122.     //
  123.     void SetSelection(const LPITEMIDLIST pidl) const;
  124.     void SetSelection(const CString& strPath) const;
  125.  
  126.     //
  127.     // Call SetStatusText to set the text in the Status area in the active dialog.  strText is
  128.     // the text to be displayed.
  129.     // NOTE -- This function should only be called within overrides of OnInit and OnSelChanged.
  130.     //
  131.     void SetStatusText(const CString& strText) const;
  132.  
  133. private:
  134.     static int __stdcall BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData);
  135.  
  136.     typedef std::auto_ptr<char> AUTO_STR;
  137.     CString m_pchTitle;
  138.  
  139.     BROWSEINFO m_bi;
  140.     TCHAR m_szSelected[MAX_PATH];
  141.     CString m_strPath;
  142.     HWND m_hwnd;
  143. };
  144.  
  145. inline UINT CBrowseForFolder::GetFlags() const
  146. {
  147.     return m_bi.ulFlags;
  148. }
  149.  
  150. inline int CBrowseForFolder::GetImage() const
  151. {
  152.     return m_bi.iImage;
  153. }
  154.  
  155. #endif // __SHELLBROWSER_H__
  156.